package com.inossem.utils.io;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * @author leij
 * @time 2017/6/3 12:46
 */
public class IOUtils {

    public static void clear(Context context, String name) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(name,
                Activity.MODE_PRIVATE);
        Editor editor = sharedPreferences.edit();
        editor.clear();
        editor.apply();
    }

    public static void remove(Context context, String name, String key) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(name,
                Activity.MODE_PRIVATE);
        Editor editor = sharedPreferences.edit();
        editor.remove(key);
        editor.apply();
    }

    public static void putString(Context context, String name, String key, String value) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(name,
                Activity.MODE_PRIVATE);
        Editor editor = sharedPreferences.edit();
        editor.putString(key, value);
        editor.apply();
    }

    public static void putInt(Context context, String name, String key, int value) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(name,
                Activity.MODE_PRIVATE);
        Editor editor = sharedPreferences.edit();
        editor.putInt(key, value);
        editor.apply();
    }

    public static void putLong(Context context, String name, String key, long value) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(name,
                Activity.MODE_PRIVATE);
        Editor editor = sharedPreferences.edit();
        editor.putLong(key, value);
        editor.apply();
    }

    public static void putBoolean(Context context, String name, String key, boolean value) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(name,
                Activity.MODE_PRIVATE);
        Editor editor = sharedPreferences.edit();
        editor.putBoolean(key, value);
        editor.apply();
    }

    public static String getString(Context context, String name, String key, String defaultValue) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(name,
                Activity.MODE_PRIVATE);
        return sharedPreferences.getString(key, defaultValue);
    }

    public static int getInt(Context context, String name, String key, int defaultValue) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(name,
                Activity.MODE_PRIVATE);
        return sharedPreferences.getInt(key, defaultValue);
    }

    public static long getLong(Context context, String name, String key, long defaultValue) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(name,
                Activity.MODE_PRIVATE);
        return sharedPreferences.getLong(key, defaultValue);
    }

    public static boolean getBoolean(Context context, String name, String key, boolean defaultValue) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(name,
                Activity.MODE_PRIVATE);
        return sharedPreferences.getBoolean(key, defaultValue);
    }

}
